package cn.tedu.micro.demo.stock.service.impl;

import cn.tedu.micro.demo.common.pojo.po.StockPO;
import cn.tedu.micro.demo.stock.mapper.StockMapper;
import cn.tedu.micro.demo.stock.service.StockService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StockServiceImpl implements StockService {
    @Autowired
    private StockMapper stockMapper;

    @Override
    public void updateStock(String productCode, Integer count) {
        UpdateWrapper<StockPO> updateWrapper = new UpdateWrapper<>();  // 创建更新条件对象
        updateWrapper.setSql("stock = stock-" + count);
        updateWrapper.eq("product_code", productCode);
        stockMapper.update(null, updateWrapper);  // PO类传null，使用对象的非空属性拼接set
    }
}
